package com.jse.sms;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import org.nutz.http.Http;
import org.nutz.http.Response;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class Sms {
	
	Log log = Logs.get();
	
	@Autowired
	PropertiesProxy conf;

	public Object send(String phone,String content) {
		try {
			content = URLEncoder.encode(content, "GBK");
			content += conf.get("sms.text");
		} catch (UnsupportedEncodingException e) {
			log.info("sms content to GBK err:",e);
		}  
		String sms_url=conf.get("sms.url");
		String url = new String(sms_url+"?CorpID="
		+conf.get("sms.id")
		+"&Pwd="+conf.get("sms.pwd")
		+"&Mobile="+phone+"&Content=" + content);
		Response res = Http.get(url);
		return res.getContent();
	}
	
}
